<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>2_在controller中使用过滤器</title>
    <script src="../lib/angularjs.js"></script>
</head>


<body data-ng-app="myApp" data-ng-controller="myCtrl">
    <!-- 使用html5的方式书写ng指令 -->
    <button data-ng-click="func(true)">升序</button>
    <button data-ng-click="func(false)">降序</button>
    <div>
        {{arr}}
    </div>
</body>

<script>
    const myApp = angular.module("myApp", [])
    myApp.controller("myCtrl", ["$scope", "$filter", function ($scope, $filter) {
        $scope.arr = [{ city: "guangzhou", id: 1, place: "nan" }, { city: "beijing", id: 2, place: "bei" }, { city: "shanghai", id: 3, place: "dong" }]
        $scope.func = function (bool) {
            console.log(bool);
            $scope.arr = $filter("orderBy")($scope.arr, "id", bool)
        }
    }])
</script>

</html>